/*
 * @Author: andarm andarm@foxmail.com
 * @Date: 2023-07-23 20:20:05
 * @LastEditors: andarm andarm@foxmail.com
 * @LastEditTime: 2023-07-30 21:02:39
 * @FilePath: \develop_library\c_lib\bits.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 *
 */
#ifndef _BITS_H_
#define _BITS_H_


/* bit operations */
#define REG64(addr) (*(volatile uint64_t *)(uint32_t)(addr))
#define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
#define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
#define REG8(addr) (*(volatile uint8_t *)(uint32_t)(addr))
#define BIT(x) ((uint32_t)((uint32_t)0x01U << (x)))
#define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
#define GET_BITS(regval, start, end) (((regval)&BITS((start), (end))) >> (start))
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
#define CPL_BIT(value,bit) (value^=(1<<bit))   //取反指定位
#define SET_BIT(value,bit) (value|=(1<<bit))   //置位指定位
#define CLR_BIT(value,bit) (value&=~(1<<bit))  //清零指定位

//Big-endian and little endian switch
#define BigLittleSwap16(A) ((((uint16_t)(A)&0xff00) >> 8) | (((uint16_t)(A)&0x00ff) << 8))

// #define BigLittleSwap32(A)        ((((uint32)(A) & 0xff000000) >> 24) |
//                                                        (((uint32)(A) & 0x00ff0000) >> 8) |
//                                                        (((uint32)(A) & 0x0000ff00) << 8) |
//                                                        (((uint32)(A) & 0x000000ff) << 24))



#endif